/*
 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
 */

#ifndef WLT_3408_NZ_H
#define WLT_3408_NZ_H

#include <stddef.h>
#include <sys/types.h>
#include "aos/hal/gpio.h"
#include "aos/hal/uart.h"

#ifdef __cplusplus
extern "C" {
#endif
#define ZIGBEE_UART_DEFAULT_TIMEOUT    3000
#define PACKET_MAX_PAYLOAD_LENGTH  64

typedef enum {
    WORKMODE_HOST = 0,
    WORKMODE_TERMINAL,
    WORKMODE_HOST_RELAY,
    WORKMODE_TERMINAL_RELAY,
    WORKMODE_MAX
}en_workmode_t;

typedef enum {
    RF_DATARATE_250K = 0,
    RF_DATARATE_500K,
    RF_DATARATE_1M,
    RF_DATARATE_MAX
}en_rf_datarate_t;

typedef enum {
    SENDMODE_UNICAST = 0,
    SENDMODE_BROADCAST,
    SENDMODE_MAX
}en_sendmode_t;

typedef enum {
    RF_CHANNEL_11 = 0x0B,
    RF_CHANNEL_12,
    RF_CHANNEL_13,
    RF_CHANNEL_14,
    RF_CHANNEL_15,
    RF_CHANNEL_16,
    RF_CHANNEL_17,
    RF_CHANNEL_18,
    RF_CHANNEL_19,
    RF_CHANNEL_20,
    RF_CHANNEL_21,
    RF_CHANNEL_22,
    RF_CHANNEL_23,
    RF_CHANNEL_24,
    RF_CHANNEL_25,
    RF_CHANNEL_26,
    RF_CHANNEL_MAX
}en_rf_channel_t;

#ifdef __cplusplus
}
#endif

/**
 * Get wlt3048 zigbee module init
 *
 * @param[in]  pst_poweron_pin  module enable pin, 
 *  param[in]  pst_comm_uart    module control uart
 *
 * @return  0 : on success, other : fail to init device
 */

int32_t wlt3408nz_dev_init(gpio_dev_t *pst_poweron_pin, uart_dev_t *pst_comm_uart);

/**
 * Get wlt3048 zigbee module local address
 *
 * @param[out]  pus_localaddr  local address value
 *
 * @return  0 : on success, other : fail to get local address
 */
int32_t wlt3408nz_get_local_addr(uint16_t *pus_localaddr);

/**
 * Set wlt3048 zigbee module local address
 *
 * @param[in]  local_addr  local address value
 *
 * @return  0 : on success, other : fail to set local address
 */

int32_t wlt3408nz_set_local_addr(uint16_t local_addr);

/**
 * Get wlt3048 zigbee module work mode
 *
 * @param[out]  pucworkmode  work mode value
 *
 * @return  0 : on success, other : fail to get work mode 
 */
int32_t wlt3408nz_get_dev_work_mode(uint8_t *pucworkmode);


/**
 * Set wlt3048 zigbee module work mode 
 *
 * @param[in]  workmode  work mode  value
 *
 * @return  0 : on success, other : fail to set work mode 
 */
int32_t wlt3408nz_set_dev_work_mode(uint8_t workmode);

/**
 * Get wlt3048 zigbee module dest address
 *
 * @param[out]  pusdest_addr dest address value
 *
 * @return  0 : on success, other : fail to get dest address
 */
int32_t wlt3408nz_get_dest_addr(uint16_t *pusdest_addr);

/**
 * Set wlt3048 zigbee module dest address
 *
 * @param[in]  dest_addr  dest address value
 *
 * @return  0 : on success, other : fail to set dest address
 */
int32_t wlt3408nz_set_dest_addr(uint16_t dest_addr);

/**
 * Get wlt3048 zigbee module rf datarate
 *
 * @param[out]  pucdatarate rf datarate value
 *
 * @return  0 : on success, other : fail to get rf datarate
 */
int32_t wlt3408nz_get_rf_datarate(uint8_t *pucdatarate);

/**
 * Set wlt3048 zigbee module rf datarate
 *
 * @param[in]  rf_datarate  rf datarate value
 *
 * @return  0 : on success, other : fail to set rf datarate
 */
int32_t wlt3408nz_set_rt_datarate(uint8_t rf_datarate);

/**
 * Get wlt3048 zigbee module send mode
 *
 * @param[out]  pucsendmode send mode value
 *
 * @return  0 : on success, other : fail to get  send mode
 */
int32_t wlt3408nz_get_sendmode(uint8_t *pucsendmode);

/**
 * Set wlt3048 zigbee module send mode
 *
 * @param[in]  sendmode  send mode value
 *
 * @return  0 : on success, other : fail to set send mode
 */
int32_t wlt3408nz_set_sendmode(uint8_t sendmode);

/**
 * Get wlt3048 zigbee module rf powerlevel
 *
 * @param[out]  pucpowerlevel rf powerlevel value
 *
 * @return  0 : on success, other : fail to get rf powerlevel
 */
int32_t wlt3408nz_get_rf_powerlevel(uint8_t *pucpowerlevel);

/**
 * Set wlt3048 zigbee module rf powerlevel
 *
 * @param[in]  rf_powerlevel rf powerlevel value
 *
 * @return  0 : on success, other : fail to set rf powerlevel
 */
int32_t wlt3408nz_set_rf_powerlevel(uint8_t rf_powerlevel);

/**
 * Get wlt3048 zigbee module rf retry num
 *
 * @param[out]  pucretrynum rf retry num value
 *
 * @return  0 : on success, other : fail to get rf retry num
 */
int32_t wlt3408nz_get_rf_retry_num(uint8_t *pucretrynum);

/**
 * Set wlt3048 zigbee module rf retry num
 *
 * @param[in]  rf_retrynum rf retry num value
 *
 * @return  0 : on success, other : fail to set rf retry num
 */
int32_t wlt3408nz_set_rf_retry_num(uint8_t rf_retrynum);

/**
 * Get wlt3048 zigbee module rf retry timeout
 *
 * @param[out]  pusretrytimeout rf retry timeout value
 *
 * @return  0 : on success, other : fail to get rf retry timeout
 */
int32_t wlt3408nz_get_rf_retry_timeout(uint16_t *pusretrytimeout);

/**
 * Set wlt3048 zigbee module rf retry timeout
 *
 * @param[in]  rf_retrytimeout rf retry timeout value
 *
 * @return  0 : on success, other : fail to set rf retry timeout
 */
int32_t wlt3408nz_set_rf_retry_timeout(uint16_t rf_retrytimeout);

/**
 * Get wlt3048 zigbee module rf channel
 *
 * @param[out]  pucrfchannel rf channel value
 *
 * @return  0 : on success, other : fail to get rf channel
 */
int32_t wlt3408nz_get_rf_channel(uint8_t *pucrfchannel);

/**
 * Set wlt3048 zigbee module rf channel
 *
 * @param[in]  rf_channel rf retry channel
 *
 * @return  0 : on success, other : fail to set rf channel
 */
int32_t wlt3408nz_set_rf_channel(uint8_t rf_channel);

/**
 * zigbee module search
 *
 * @param[in]   expect_num       expect number
 * @param[out]  puc_detectednum  dectected module number
 * @param[out]  pus_devaddr      dectected device address
 *
 * @return  0 : on success, other : fail to seach zigbee module
 */
int32_t wlt3408nz_dev_search(uint8_t expect_num, uint8_t *puc_detectednum, uint16_t *pus_devaddr);

/**
 * zigbee module device online check
 *
 * @param[in]   usdevaddr       module device address
 *
 * @return  0 : on success, other : fail to set rf channel
 */
int32_t wlt3408nz_dev_online_check(uint16_t usdevaddr);

/**
 * zigbee module device send data
 *
 * @param[in]   destaddr       module dest address
 * @param[in]   pdata          point to data to be send
 * @param[in]   length         data length to be sent
 * @return  0 : on success, other : fail to send
 */
int32_t wlt3408nz_dev_data_send(uint16_t destaddr, uint8_t *pdata, uint8_t length);

/**
 * zigbee module device recv data
 *
 * @param[in]   pussrcaddr     recv data src address
 * @param[in]   pdata          point to the recv data store adrress
 * @param[in]   length         data length wanted to be recved
 * @return  0 : on success, other : fail to send
 */
int32_t wlt3408nz_dev_data_recv(uint16_t *pussrcaddr, uint8_t *pdata, uint8_t length);



#endif  /* WLT_3408_NZ_H */

